﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SSS.AlphaNN.Components
{

    public partial class Sink : DataMedium
    {
        /// <summary>
        /// Конструктор
        /// </summary>
        public Sink(UserControl parent)
        {
            InitializeComponent();

            Visible = false;

            this.Parent = parent;
            PathFileDb = String.Empty;
            //SetSlotsAmount( 5 );

            this.BackColor = Color.GhostWhite;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="slotsAmount"></param>
        public override void SetSlotsAmount(int slotsAmount)
        {
            int offset = 5;
            int innerSpace = 2;

            Slot slot = new Slot();

            for (int i = 0; i < slotsAmount; i++)
            {
                slot = new Slot();

                slot.Name = "slot1_" + (i + 1).ToString();
                (this.Parent as WorkGround).Controls.Add(slot);//вот эта строчка  меня убила
                base.Slots.Add(slot);

                base.Slots[i].Left = this.NoneScaleLocation.X + this.NoneScaleSize.Width - slot.NoneScaleSize.Width;
                base.Slots[i].Top = this.NoneScaleLocation.Y + offset;

                slot.Visible = false;
                slot.Owner = this;

                offset += slot.Height + innerSpace;
            }

            base.NoneScaleSize = new Size(base.NoneScaleSize.Width, slot.Top - this.NoneScaleLocation.Y + slot.Height + 5);

            this.Refresh();
        }

        /// <summary>
        /// 
        /// </summary>
        public override void Scale()
        {
            base.Scale();

            if (base.Slots.Count > 0)
            {
                Slot slot = new Slot();

                for (int i = 0; i < base.Slots.Count; i++)
                {
                    slot = base.Slots[i];

                    slot.Size = new Size((int)(slot.NoneScaleSize.Width + slot.NoneScaleSize.Width * Zoom / 100), (int)(slot.NoneScaleSize.Height + slot.NoneScaleSize.Height * Zoom / 100));
                }
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public override void ReLocate()
        {
            base.ReLocate();

            if (base.Slots.Count > 0)
            {
                int offset = 5 + (int)(5 * Zoom / 100);
                int innerSpace = 2 + (int)(2 * Zoom / 100);

                Slot slot = new Slot();

                for (int i = 0; i < base.Slots.Count; i++)
                {
                    slot = base.Slots[i];

                    base.Slots[i].Left = this.Location.X;
                    //base.Slots[i].Left = this.Location.X + this.Width - slot.Width;
                    base.Slots[i].Top = this.Location.Y + offset;

                    offset += slot.Height + innerSpace;
                }

                //base.NoneScaleSize = new Size( base.NoneScaleSize.Width, slot.Top - this.NoneScaleLocation.Y + slot.Height + 5 );
            }
        }
    }
}
